#ifndef TCP_THREAD_H
#define TCP_THREAD_H

#include "QObject"
#include <QThread>
#include <QHostAddress>
#include "QTcpServer"
#include "QTcpSocket"
#include "QMutex"
#include "QString"
#include "util/util.h"
#include <string.h>




class tcp_thread : public QThread
{
    Q_OBJECT

public:
    tcp_thread(QHostAddress ip, QString port, QObject *parent = nullptr);
    ~tcp_thread();

    QHostAddress client_ip;
    quint16 client_port;

    bool TCPthread_start_flag;
    bool TCPthread_connect_flag;
    bool TCPthread_send_flag;
    bool TCPthread_receive_flag;

    void mutex_Stop();
    void mutex_GoOn();

    QTcpServer *tcp_server;
    QTcpSocket *tcp_socket;

    void ParseTcpReceivedData(QString &data, Techn_Param_ptr tech_param);
    void removeFirstElement(QString &data);
    bool isIoParam(const XMLElement *elementptr);
    bool isAlarmParam(const XMLElement *elementptr);


private:
    QMutex mutex;

protected:
    void run();

private slots:
    void ConnectNewClient();
    void SendServerMessage();
    void RecvClientMessage();
    void DisConnectNewClient();

signals:
    void readyWrite();
    void AbortTcpConnect();
};

#endif // TCP_THREAD_H
